package com.woniu.bank.service.impl;

import com.github.pagehelper.PageHelper;
import com.woniu.bank.dto.AgreementGroupDTO;
import com.woniu.bank.dto.NewAgreementDTO;
import com.woniu.bank.entity.Agreement;
import com.woniu.bank.mapper.AgreementMapper;
import com.woniu.bank.service.AgreementService;
import com.woniu.bank.vo.AgreementDefaultDataVO;
import com.woniu.bank.vo.AgreementGroupMemberVO;
import com.woniu.bank.vo.AgreementGroupVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 联保协议实现类
 *
 * @author 晨星
 * @date 2023/1/9 15:33
 **/
@Service
public class AgreementServiceImpl implements AgreementService {

    private final AgreementMapper agreementMapper;

    public AgreementServiceImpl(AgreementMapper agreementMapper) {
        this.agreementMapper = agreementMapper;
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return agreementMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Agreement record) {
        return agreementMapper.insert(record);
    }

    @Override
    public int insertSelective(Agreement record) {
        return agreementMapper.insertSelective(record);
    }

    @Override
    public Agreement selectByPrimaryKey(Long id) {
        return agreementMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Agreement record) {
        return agreementMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Agreement record) {
        return agreementMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<AgreementGroupVO> select(AgreementGroupDTO agreementGroupDTO) {
        PageHelper.startPage(agreementGroupDTO.getCurrentPage(), agreementGroupDTO.getPageSize());
        return agreementMapper.select(agreementGroupDTO);
    }

    @Override
    public List<AgreementGroupMemberVO> selectGroupMember(Integer id) {
        return agreementMapper.selectGroupMember(id);
    }

    @Override
    public AgreementDefaultDataVO returnDefaultData(AgreementGroupVO agreement) {
        return agreementMapper.returnDefaultData(agreement);
    }

    @Override
    public int insertAgreement(NewAgreementDTO agreement) {
        return agreementMapper.updateAgreement(agreement);
    }

    @Override
    public int terminationAgreement(AgreementGroupVO agreement) {
        agreement.setAgreementStatus("终止");
        return agreementMapper.terminationAgreement(agreement);
    }

    @Override
    public int cancellationAgreement(AgreementGroupVO agreement) {
        agreement.setAgreementStatus("废弃");
        return agreementMapper.cancellationAgreement(agreement);
    }
}

